<?php

namespace Dyadmin\Controller;

use Think\Controller;

class LoginController extends Controller {
	public function index() {
		$array ['web_name'] = C ( 'WEB_NAME' );
		$array ['soft_copyright'] = C ( 'SOFT_COPYRIGHT' );
		$this->assign ( $array );
		
		$this->display ();
	}
	public function verify_code() {
		ob_clean ();
		$Verify = new \Think\Verify ();
		$Verify->useNoise = false;
		$Verify->fontSize = 28;
		$Verify->length = 4;
		$Verify->useCurve = false;
		$Verify->bg = array (
				92,
				189,
				170 
		);
		$Verify->entry ( 'imgcode' );
	}
	public function chkLogin() {
		$data = I ( 'post.' );
		$result ['status'] = 'n';
		$result ['info'] = "";
		
		$adminname = strtolower ( trim ( $data ['TxtUserName'] ) );
		$password = strtolower ( trim ( $data ['TxtUserPass'] ) );
		$passcode = strtolower ( trim ( $data ['TxtCheckCode'] ) );
		
		if (!check_verify ( $passcode, 'imgcode' )) {
			$result ['info'] = "验证码输入错误！";
			
			$this->ajaxReturn ( $result, 'JSON' );
			exit ();
		} else {
			$pwd = sha1 ( $password );
			$ret = D ( 'Admin' )->find_login ( $adminname, $pwd );
			if ($ret [0] == 'success') {
				
				$result ['status'] = 'y';
				$result ['info'] = "登入成功";
				$this->ajaxReturn ( $result, 'JSON' );
			} else {
				$result ['info'] = "用户名或密码输入错误！";
				$this->ajaxReturn ( $result, 'JSON' );
				exit ();
			}
		}
	}
	
	public  function login_out(){
		
		
		$login_session= session('login_session');
		if(!empty($login_session)){
			
		}
		
		session('login_session',null);
		setcookie('login_session','', time() - 3600, '/');
		

		session('admin_id',null);
		setcookie('admin_id','', time() - 3600, '/');
		$this->redirect('Dyadmin/login/index');
		
	}
}